package com.wwj.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Auser on 2016/12/17.
 */
public class SFZUtil {

    public final static String ID_CARD_1 = "/^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$/";
    public final static String ID_CARD_2 = "/^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$/";


    /**
     * 验证身份证号码合法性
     * @param number
     * @return
     */
    public static boolean idCardNumber(String number){
        String rgx = "^\\d{15}|^\\d{17}([0-9]|X|x)$";
        return isCorrect(rgx, number);
    }

    public static void main(String[] args) {
        System.out.println(idCardNumber("431103198913120301"));
    }

    //正则验证
    public static boolean isCorrect(String rgx, String res)
    {
        Pattern p = Pattern.compile(rgx);
        Matcher m = p.matcher(res);
        return m.matches();
    }
}
